<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改抄表信息')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-elecMeter-edit" th:object="${sjMeterReading}">
            <input name="ammeterId" class="form-control" type="hidden" th:field = "*{ammeterId}">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">楼层：</label>
                <div class="col-sm-8">
                    <!--<input name="floorName" class="form-control" id="floorName" type="text" th:field="*{floorName}" required>-->

                    <select name="floorName" class="form-control" id="floorName" th:field="*{floorName}" onchange="initDegreeAll()" required>
                        <option th:each="floorInfo:${floorInfos}" th:text="${floorInfo.floorName}" th:value="${floorInfo.floorName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required" >A表度数：</label>
                <div class="col-sm-8">
                    <input name="degreeIssueA" id="degreeIssueA" class="form-control" onblur="initDegreeAll()" th:field="*{degreeIssueA}" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required" >B表度数：</label>
                <div class="col-sm-8">
                    <input name="degreeIssueB" id="degreeIssueB" class="form-control" onblur="initDegreeAll()" th:field="*{degreeIssueB}" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required" >C表度数：</label>
                <div class="col-sm-8">
                    <input name="degreeIssueC" id="degreeIssueC" class="form-control" onblur="initDegreeAll()" th:field="*{degreeIssueC}" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required" >D表度数：</label>
                <div class="col-sm-8">
                    <input name="degreeIssueD" id="degreeIssueD" class="form-control" onblur="initDegreeAll()" th:field="*{degreeIssueD}" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">本期总度数：</label>
                <div class="col-sm-8">
                    <input name="degreeIssue" id="degreeIssue" value="0" class="form-control" type="text" th:field = "*{degreeIssue}" required readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">本期抄表时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input autocomplete="off" type="text" class="time-input form-control" id="issueDate" th:value="${#dates.format(sjMeterReading.issueDate, 'yyyy-MM-dd')}" placeholder="请填写日期" name="issueDate" required/>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required" >电表状态：</label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="status" th:checked = "${sjMeterReading.status=='1'?true:false}">
                        <span></span>
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text" th:field = "*{remark}">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "sujian/elecMeter"

        $(function () {
            initSelect2();
        })

        function initSelect2(){
            $("select[name='ammeterName']").select2({
                placeholder:"--请选择电表--",
                allowClear:true
            });
        }

        function initDegreeAll(){
            var degreeAll = parseFloat(0);
            if($('#degreeIssueA').val()!=null&&$('#degreeIssueA').val()!=''){
                degreeAll+=parseFloat($('#degreeIssueA').val());
            }
            if($('#degreeIssueB').val()!=null&&$('#degreeIssueB').val()!=''){
                degreeAll+=parseFloat($('#degreeIssueB').val());
            }
            if($('#degreeIssueC').val()!=null&&$('#degreeIssueC').val()!=''){
                degreeAll+=parseFloat($('#degreeIssueC').val());
            }
            if($('#floorName').val()!="1"){
                if($('#degreeIssueD').val()!=null&&$('#degreeIssueD').val()!=''){
                    degreeAll+=parseFloat($('#degreeIssueD').val());
                }
            }
            degreeAll = degreeAll.toFixed(2);
            $('#degreeIssue').val(degreeAll)
        }

        $.validator.addMethod("degreeAReg",function (value,element) {
            var reg = new RegExp(/^[0-9]+(.[0-9]+)?$/);
            return this.optional(element) || reg.test(value)
        })
        $.validator.addMethod("degreeBReg",function (value,element) {
            var reg = new RegExp(/^[0-9]+(.[0-9]+)?$/);
            return this.optional(element) || reg.test(value)
        })
        $.validator.addMethod("degreeCReg",function (value,element) {
            var reg = new RegExp(/^[0-9]+(.[0-9]+)?$/);
            return this.optional(element) || reg.test(value)
        })
        $.validator.addMethod("degreeDReg",function (value,element) {
            var reg = new RegExp(/^[0-9]+(.[0-9]+)?$/);
            return this.optional(element) || reg.test(value)
        })
        $("#form-elecMeter-add").validate({
            onkeyup:false,
            rules:{
                degreeIssueA:{
                    degreeAReg:true
                },
                degreeIssueB:{
                    degreeBReg:true
                },
                degreeIssueC:{
                    degreeCReg:true
                },
                degreeIssueD:{
                    degreeDReg:true
                }
            },
            messages:{
                degreeIssueA:{
                    degreeAReg: "请输入正确电表度数"
                },
                degreeIssueB:{
                    degreeBReg: "请输入正确电表度数"
                },
                degreeIssueC:{
                    degreeCReg: "请输入正确电表度数"
                },
                degreeIssueD:{
                    degreeDReg: "请输入正确电表度数"
                }
            },
            focusCleanup: true
        });
        function submitHandler() {
            if ($.validate.form()) {
                var data = $('#form-elecMeter-edit').serializeArray();
                var status = $("input[id='status']").is(':checked')==true?1:0;
                data.push({"name":"status","value":status})
                $.operate.save(prefix + "/editSave", data);
            }
        }

    </script>
</body>
</html>